package com.baike.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baike.entity.Student;
import com.baike.service.StudentClientService;

@RestController
@RequestMapping("/student")
public class StudentConsumerController {

	
	@Autowired
	private StudentClientService studentClientService;
	
	//private final static String PRE_HOST="http://localhost:1001";
	//private final static String PRE_HOST="http://MICROSERVICE-STUDENT";
	
	/**
     * 添加或者修改学生信息
     * @param student
     * @return
     */
	@PostMapping("/save")
	private boolean save(Student student){
		try{
			return studentClientService.save(student);
		}catch(Exception e){
			return false;
		}
		
	}
	
	/**
	 * 查询学生信息
	 * @return
	 */
	@GetMapping("/list")
	public List<Student> findAll(){
		return studentClientService.list();
	}

	/**
	 * 根据id查询学生信息
	 * @return
	 */
	@GetMapping(value="/get/{id}")
	public Student get(@PathVariable("id") Integer id){
		return studentClientService.get(id);
	}
	
	/**
	 * 根据id删除学生信息
	 * @return
	 */
	@GetMapping(value="/delete/{id}")
	public boolean delete(@PathVariable("id") Integer id){
		try{
			return studentClientService.delete(id);
		}catch(Exception e){
			return false;
		}
	}
	/**
	 * 根据id删除学生信息
	 * @return
	 */
	@GetMapping(value="/getInfo")
	@ResponseBody
	public Map<String,Object> getInfo(){
	    return studentClientService.getInfo();
	}
}
